﻿namespace Sai.Core.Introspection
{
	using System;
using System.Collections.Generic;
using System.Text;

	/// <summary>
	/// Holds information about interface declarations.
	/// </summary>
	public class InterfaceDeclaration : ReferenceTypeDeclaration, ITypeDeclaration, IEquatable<ITypeDeclaration>, ISourceCodeProvider
	{
		public InterfaceDeclaration()
			: base()
		{
		}

		public InterfaceDeclaration(TypeName typeName)
			: base(typeName)
		{
		}

		public InterfaceDeclaration(TypeName typeName, ObsoleteMarker marker)
			: base(typeName, marker)
		{
		}

		public TypeTaxonomy Taxonomy
		{
			get
			{
				return TypeTaxonomy.Interface;
			}
		}

		public bool MatchesType(ITypeDeclaration other)
		{
			return this.Taxonomy == other.Taxonomy;
		}

        public SourceCode ToCode()
        {
            SourceCode code = new SourceCode();

            code.Add(new KeywordTag("public"));
            code.Add(new KeywordTag("interface"));
            code.Add(this.TypeName.ToCode());

            if (this.Interfaces.Count > 0)
            {
                code.Add(new PunctuationTag(":"));

                for (int i = 0; i < this.Interfaces.Count; ++i)
                {
                    TypeName t = this.Interfaces[i];

                    code.Add(new TypeNameTag(t.Name));

                    if (i < this.Interfaces.Count - 1)
                    {
                        code.Add(new PunctuationTag(","));
                    }
                }
            }

            return code;
        }
    }
}
